<?php
declare(strict_types=1);
namespace Field;

class QuestionPostConst
{
    public const pk='PostID';
    public const index=['PostID'];
	public const fields=['ThreadID','PostID','UserID','IsFirst','UpdateAt','CreateAt','UserIP','Images','Files','DocType','Likes','CaiNa','Status','Message'];
	public const comment=['ThreadID'=>'','PostID'=>'','UserID'=>'','IsFirst'=>'1首帖','UpdateAt'=>'','CreateAt'=>'','UserIP'=>'','Images'=>'','Files'=>'','DocType'=>'类型，0: html, 1: txt; 2: markdown','Likes'=>'','CaiNa'=>'采纳','Status'=>'','Message'=>''];
	/*
    * @Field ThreadID
    * @Type int(10) unsigned
    * @Collation 
    * @Null NO
    * @Key MUL
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const ThreadID = 'ThreadID';
    /*
    * @Field PostID
    * @Type int(10) unsigned
    * @Collation 
    * @Null NO
    * @Key PRI
    * @Default 
    * @Extra auto_increment
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const PostID = 'PostID';
    /*
    * @Field UserID
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const UserID = 'UserID';
    /*
    * @Field IsFirst
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 1首帖
    */
    public const IsFirst = 'IsFirst';
    /*
    * @Field UpdateAt
    * @Type timestamp
    * @Collation 
    * @Null YES
    * @Key 
    * @Default CURRENT_TIMESTAMP
    * @Extra on update CURRENT_TIMESTAMP
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const UpdateAt = 'UpdateAt';
    /*
    * @Field CreateAt
    * @Type timestamp
    * @Collation 
    * @Null YES
    * @Key 
    * @Default CURRENT_TIMESTAMP
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const CreateAt = 'CreateAt';
    /*
    * @Field UserIP
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const UserIP = 'UserIP';
    /*
    * @Field Images
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const Images = 'Images';
    /*
    * @Field Files
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const Files = 'Files';
    /*
    * @Field DocType
    * @Type int(11) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 2
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 类型，0: html, 1: txt; 2: markdown
    */
    public const DocType = 'DocType';
    /*
    * @Field Likes
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const Likes = 'Likes';
    /*
    * @Field CaiNa
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 采纳
    */
    public const CaiNa = 'CaiNa';
    /*
    * @Field Status
    * @Type int(11)
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const Status = 'Status';
    /*
    * @Field Message
    * @Type text
    * @Collation utf8mb4_general_ci
    * @Null YES
    * @Key 
    * @Default 
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 
    */
    public const Message = 'Message';
}

class QuestionPostColumns
{
public  int $ThreadID;
   public  int $PostID;
   public  int $UserID=0;
   public  int $IsFirst=0;
   public  ?string $UpdateAt='';
   public  ?string $CreateAt='';
   public  int $UserIP=0;
   public  int $Images=0;
   public  int $Files=0;
   public  int $DocType=0;
   public  int $Likes=0;
   public  int $CaiNa=0;
   public  int $Status=0;
   public  ?string $Message='';
	public function toArray():array
	{
		return [
'ThreadID'=>$this->ThreadID,
    'PostID'=>$this->PostID,
    'UserID'=>$this->UserID,
    'IsFirst'=>$this->IsFirst,
    'UpdateAt'=>$this->UpdateAt,
    'CreateAt'=>$this->CreateAt,
    'UserIP'=>$this->UserIP,
    'Images'=>$this->Images,
    'Files'=>$this->Files,
    'DocType'=>$this->DocType,
    'Likes'=>$this->Likes,
    'CaiNa'=>$this->CaiNa,
    'Status'=>$this->Status,
    'Message'=>$this->Message,        ];
	}
}

class QuestionPostRow
{
	public QuestionPostColumns $data;
	public function toArray():array
	{
		return $this->data->toArray();
    }

    public function getValue(string $field):string|int|null
    {
        return match ($field){
        'ThreadID' => $this->data->ThreadID,
        'PostID' => $this->data->PostID,
        'UserID' => $this->data->UserID,
        'IsFirst' => $this->data->IsFirst,
        'UpdateAt' => $this->data->UpdateAt,
        'CreateAt' => $this->data->CreateAt,
        'UserIP' => $this->data->UserIP,
        'Images' => $this->data->Images,
        'Files' => $this->data->Files,
        'DocType' => $this->data->DocType,
        'Likes' => $this->data->Likes,
        'CaiNa' => $this->data->CaiNa,
        'Status' => $this->data->Status,
        'Message' => $this->data->Message, default=>null
        };
    }

    public function __construct(array $data)
    {
        $this->data = new QuestionPostColumns();
        isset($data['ThreadID']) && $this->data->ThreadID = (int)$data['ThreadID'];
           isset($data['PostID']) && $this->data->PostID = (int)$data['PostID'];
           isset($data['UserID']) && $this->data->UserID = (int)$data['UserID'];
           isset($data['IsFirst']) && $this->data->IsFirst = (int)$data['IsFirst'];
           isset($data['UpdateAt']) && $this->data->UpdateAt = (string)$data['UpdateAt'];
           isset($data['CreateAt']) && $this->data->CreateAt = (string)$data['CreateAt'];
           isset($data['UserIP']) && $this->data->UserIP = (int)$data['UserIP'];
           isset($data['Images']) && $this->data->Images = (int)$data['Images'];
           isset($data['Files']) && $this->data->Files = (int)$data['Files'];
           isset($data['DocType']) && $this->data->DocType = (int)$data['DocType'];
           isset($data['Likes']) && $this->data->Likes = (int)$data['Likes'];
           isset($data['CaiNa']) && $this->data->CaiNa = (int)$data['CaiNa'];
           isset($data['Status']) && $this->data->Status = (int)$data['Status'];
           isset($data['Message']) && $this->data->Message = (string)$data['Message'];
    }
}
?>